package com.tuyan.aixiang.component;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.tuyan.aixiang.R;
import com.tuyan.aixiang.model.Mode;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ModeItem extends RelativeLayout {


    @BindView(R.id.iv_bg)
    ImageView ivBg;

    @BindView(R.id.iv_check_mask)
    ImageView ivCheckMask;

    private Mode mode;

    public ModeItem(Context context) {
        this(context, null);
    }

    public ModeItem(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ModeItem(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View contentView  = LayoutInflater.from(context).inflate(R.layout.mode_item, this);
        ButterKnife.bind(contentView, this);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ModeItem);
        int bgId = ta.getResourceId(R.styleable.ModeItem_mi_bg, 0);
        ivBg.setImageResource(bgId);
        ta.recycle();
    }

    public void setup(Mode mode) {
        this.mode = mode;
    }

    public void check() {
        this.ivCheckMask.setVisibility(VISIBLE);
    }

    public void uncheck() {
        this.ivCheckMask.setVisibility(GONE);
    }

}
